using System.Net.Sockets;
using Unity.VisualScripting;
using GameFramework.Network;
using NetworkErrorEventArgs = UnityGameFramework.Runtime.NetworkErrorEventArgs;

namespace LS.UGFUnits
{
    [UnitShortTitle("Network")]
    [UnitSurtitle("Error")]
    public sealed class NetworkError : FrameworkEventUnit<NetworkErrorEventArgs>
    {
        protected override int EventId => NetworkErrorEventArgs.EventId;
        protected override string HookName => UGFHookNames.NetworkError;

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput NetworkChannel
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput ErrorCode
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput SocketErrorCode
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput ErrorMessage
        {
            get;
            private set;
        }
        
        protected override void Definition()
        {
            base.Definition();
            NetworkChannel = ValueOutput<INetworkChannel>(nameof(NetworkChannel));
            ErrorCode = ValueOutput<NetworkErrorCode>(nameof(ErrorCode));
            SocketErrorCode = ValueOutput<SocketError>(nameof(SocketErrorCode));
            ErrorMessage = ValueOutput<string>(nameof(ErrorMessage));
        }

        protected override void AssignArguments(Flow flow, NetworkErrorEventArgs args)
        {
            base.AssignArguments(flow, args);
            flow.SetValue(NetworkChannel, args.NetworkChannel);
            flow.SetValue(ErrorCode, args.ErrorCode);
            flow.SetValue(SocketErrorCode, args.SocketErrorCode);
            flow.SetValue(ErrorMessage, args.ErrorMessage);
        }
    }
}